
** Loading data - generated in dofile: data3
use "$data\minwage_data3_2012_2015.dta", clear

** Monthly Earnings: trimmed at p1 and p99 **
replace felt_200 = . if felt_200 <= 0

bysort tline indkaar: egen p1_felt_200 = pctile(felt_200), p(1)
bysort tline indkaar: egen p99_felt_200 = pctile(felt_200), p(99)

ge felt_200_trim = felt_200
replace felt_200_trim = p1_felt_200 if p1_felt_200 > felt_200
replace felt_200_trim = p99_felt_200 if p99_felt_200 < felt_200 & felt_200 !=.

** Monthly Work Hours: trimmed at p1 and p99 **
replace timeantF12 = . if timeantF12 <= 0
replace timeantF12 = . if timeantF12 > 1000
bysort tline indkaar: egen p1_timeantF12 = pctile(timeantF12), p(1)
bysort tline indkaar: egen p99_timeantF12 = pctile(timeantF12), p(99)

ge timeantF12_trim = timeantF12
replace timeantF12_trim = p1_timeantF12 if p1_timeantF12 > timeantF12
replace timeantF12_trim = p99_timeantF12 if p99_timeantF12 < timeantF12 & timeantF12 !=.

** Indicator for Employed **
ge emplyd = felt_200_trim > 0 & felt_200 !=.

** Calculated hourly wage: trimmed at p1 and p99 **
ge calc_hrly_wage_raw = felt_200 / timeantF12
ge calc_hrly_wage = felt_200 / timeantF12

bysort tline indkaar: egen p1_calc_hrly_wage = pctile(calc_hrly_wage), p(1)
bysort tline indkaar: egen p99_calc_hrly_wage = pctile(calc_hrly_wage), p(99)

replace calc_hrly_wage = p1_calc_hrly_wage if p1_calc_hrly_wage > calc_hrly_wage
replace calc_hrly_wage = p99_calc_hrly_wage if p99_calc_hrly_wage < calc_hrly_wage & calc_hrly_wage !=.

save "$data\minwage_data4_2012_2015.dta", replace
